Root-finding algorithm